using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;

using System.Reflection;
using Gizmox.WebGUI.Common.Resources;
using Gizmox.WebGUI.Forms;

using System.IO;
using TVC.Layout;

namespace TVC.Modules.Com
{
    /// <summary>
    /// Summary description for CustomWindowPanelControl.
    /// </summary>

    [Serializable()]
    public class DB : ModuleParent, IHostedApplication
    {
        private TabControl tabControl1;
        private TabPage tbList;
        private TabPage tbDetail;
        private Label label3;
        private TextBox txtDATA_ACCESS_GROUP;
        private Label label2;
        private TextBox txtDESCRIPTION;
        private TextBox txtDB;
        private Label label1;
        private TextBox txtREPORT_TEMPLATE_DRIVER;
        private Label label4;
        private PictureBox pibDATA_ACCESS_GROUP;
        private GroupBox gbFormat;
        private Label label13;
        private TextBox txtDATE_FORMAT;
        private GroupBox gbPara;
        private Label label12;
        private TextBox txtPARAM_6;
        private Label label11;
        private TextBox txtPARAM_5;
        private Label label10;
        private TextBox txtPARAM_3;
        private TextBox txtPARAM_4;
        private Label label9;
        private TextBox txtPARAM_1;
        private Label label8;
        private Label label7;
        private TextBox txtPARAM_2;
        private TextBox textBox6;
        private TextBox textBox5;
        private Label label16;
        private TextBox txtTHOUSAND_SEPERATOR;
        private TextBox txtDECIMAL_SEPERATOR;
        private Label label15;
        private TextBox txtDECIMAL_PLACES_SUNACCOUNT;
        private TextBox txtDECIMAL_PLACES_SUNBUSINESS;
        private Label label14;
        private Label label6;
        private Label label5;
        private DataGridView dgvList;
        private DataGridViewTextBoxColumn colDB;
        private DataGridViewTextBoxColumn colDESCRIPTION;
        private BindingSource bisDB;
        private IContainer components;
        string _processStatus = "";
        //string _strType = "DB";
        string sErr = "";
        GridLayout layout = null;
        public DB()
        {
            // This call is required by the WebGUI Form Designer.
            InitializeComponent();

        }

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }
        int idAllowEditLanguage = 1;
        int idAddNew = 15;
        int idEdit = 16;
        int idDelete = 17;
        int idTransferIn = 18;
        int idTransferOut = 19;
        int idPrint = 20;






        protected override void AllowEditLanguage()
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    x.DoubleClick += Control_DoubleClick;
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    x.DoubleClick += Control_DoubleClick;
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            y.DoubleClick += Control_DoubleClick;
                    }
                }
            }

            ContextMenu menu = new ContextMenu();
            menu.MenuItems.Add(new MenuItem("Edit Language"));
            dgvList.MenuClick += dgvList_MenuClick;
            tabControl1.DoubleClick += tabMain_DoubleClick;
            dgvList.ContextMenu = menu;
        }

        protected override void LoadLanguage(string language)
        {
            foreach (Control x in tbDetail.Controls)
            {
                if (x is Label)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                }
                if (x is GroupBox || x is ExpandableGroupBox || x is Panel)
                {
                    clsConfigurarion.GetLabel(this.ToString(), x, language);
                    foreach (Control y in x.Controls)
                    {
                        if (y is Label)
                            clsConfigurarion.GetLabel(this.ToString(), y, language);
                    }
                }
            }

            if (this.Parent is HeaderedPanel)
            {
                HeaderedPanel pln = this.Parent as HeaderedPanel;
                _title = clsConfigurarion.GetLabel(this.ToString(), "", null, language);
            }
        }
        public HostedToolBarElement[] GetToolBarElements()
        {
            ArrayList objElements = new ArrayList();
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Add New", new IconResourceHandle("Add.png"), "C"));
            if (IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Edit", new IconResourceHandle("Edit.png"), "A"));
            if (IsPermis(idAddNew) && IsPermis(idEdit))
                objElements.Add(new HostedToolBarButton("Save", new IconResourceHandle("Save.png"), "S"));
            if (IsPermis(idAddNew))
                objElements.Add(new HostedToolBarButton("Copy", new IconResourceHandle("Copy.png"), "O"));
            if (IsPermis(idDelete))
                objElements.Add(new HostedToolBarButton("Delete", new IconResourceHandle("Delete.png"), "X"));
            objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idTransferIn))
                objElements.Add(new HostedToolBarButton("Transfer In", new IconResourceHandle("Down.png"), "TI"));
            if (IsPermis(idTransferOut))
                objElements.Add(new HostedToolBarButton("Transfer Out", new IconResourceHandle("Up.png"), "TO"));
            objElements.Add(new HostedToolBarSeperator());
            if (IsPermis(idPrint))
                objElements.Add(new HostedToolBarButton("Print", new IconResourceHandle("Print.png"), "P"));
            objElements.Add(new HostedToolBarButton("Refresh", new IconResourceHandle("Refresh.png"), "R"));

            return (HostedToolBarElement[])objElements.ToArray(typeof(HostedToolBarElement));
        }



        #region Component Designer generated code
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DB));
            this.tabControl1 = new Gizmox.WebGUI.Forms.TabControl();
            this.tbList = new Gizmox.WebGUI.Forms.TabPage();
            this.dgvList = new Gizmox.WebGUI.Forms.DataGridView();
            this.colDB = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.colDESCRIPTION = new Gizmox.WebGUI.Forms.DataGridViewTextBoxColumn();
            this.bisDB = new Gizmox.WebGUI.Forms.BindingSource(this.components);
            this.tbDetail = new Gizmox.WebGUI.Forms.TabPage();
            this.gbFormat = new Gizmox.WebGUI.Forms.GroupBox();
            this.label16 = new Gizmox.WebGUI.Forms.Label();
            this.txtTHOUSAND_SEPERATOR = new Gizmox.WebGUI.Forms.TextBox();
            this.txtDECIMAL_SEPERATOR = new Gizmox.WebGUI.Forms.TextBox();
            this.label15 = new Gizmox.WebGUI.Forms.Label();
            this.txtDECIMAL_PLACES_SUNACCOUNT = new Gizmox.WebGUI.Forms.TextBox();
            this.txtDECIMAL_PLACES_SUNBUSINESS = new Gizmox.WebGUI.Forms.TextBox();
            this.label14 = new Gizmox.WebGUI.Forms.Label();
            this.label6 = new Gizmox.WebGUI.Forms.Label();
            this.label5 = new Gizmox.WebGUI.Forms.Label();
            this.label13 = new Gizmox.WebGUI.Forms.Label();
            this.txtDATE_FORMAT = new Gizmox.WebGUI.Forms.TextBox();
            this.gbPara = new Gizmox.WebGUI.Forms.GroupBox();
            this.label12 = new Gizmox.WebGUI.Forms.Label();
            this.txtPARAM_6 = new Gizmox.WebGUI.Forms.TextBox();
            this.label11 = new Gizmox.WebGUI.Forms.Label();
            this.txtPARAM_5 = new Gizmox.WebGUI.Forms.TextBox();
            this.label10 = new Gizmox.WebGUI.Forms.Label();
            this.txtPARAM_3 = new Gizmox.WebGUI.Forms.TextBox();
            this.txtPARAM_4 = new Gizmox.WebGUI.Forms.TextBox();
            this.label9 = new Gizmox.WebGUI.Forms.Label();
            this.txtPARAM_1 = new Gizmox.WebGUI.Forms.TextBox();
            this.label8 = new Gizmox.WebGUI.Forms.Label();
            this.label7 = new Gizmox.WebGUI.Forms.Label();
            this.txtPARAM_2 = new Gizmox.WebGUI.Forms.TextBox();
            this.textBox6 = new Gizmox.WebGUI.Forms.TextBox();
            this.textBox5 = new Gizmox.WebGUI.Forms.TextBox();
            this.pibDATA_ACCESS_GROUP = new Gizmox.WebGUI.Forms.PictureBox();
            this.txtREPORT_TEMPLATE_DRIVER = new Gizmox.WebGUI.Forms.TextBox();
            this.label4 = new Gizmox.WebGUI.Forms.Label();
            this.label3 = new Gizmox.WebGUI.Forms.Label();
            this.txtDATA_ACCESS_GROUP = new Gizmox.WebGUI.Forms.TextBox();
            this.label2 = new Gizmox.WebGUI.Forms.Label();
            this.txtDESCRIPTION = new Gizmox.WebGUI.Forms.TextBox();
            this.txtDB = new Gizmox.WebGUI.Forms.TextBox();
            this.label1 = new Gizmox.WebGUI.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).BeginInit();
            this.tabControl1.SuspendLayout();
            this.tbList.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisDB)).BeginInit();
            this.tbDetail.SuspendLayout();
            this.gbFormat.SuspendLayout();
            this.gbPara.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pibDATA_ACCESS_GROUP)).BeginInit();
            this.SuspendLayout();
            // 
            // tabControl1
            // 
            this.tabControl1.Alignment = Gizmox.WebGUI.Forms.TabAlignment.Bottom;
            this.tabControl1.Appearance = Gizmox.WebGUI.Forms.TabAppearance.Workspace;
            this.tabControl1.Controls.Add(this.tbList);
            this.tabControl1.Controls.Add(this.tbDetail);
            this.tabControl1.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(3, 3);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(601, 442);
            this.tabControl1.TabIndex = 0;
            // 
            // tbList
            // 
            this.tbList.Controls.Add(this.dgvList);
            this.tbList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbList.Location = new System.Drawing.Point(4, 22);
            this.tbList.Name = "tbList";
            this.tbList.Size = new System.Drawing.Size(593, 416);
            this.tbList.TabIndex = 0;
            this.tbList.Text = "List";
            // 
            // dgvList
            // 
            this.dgvList.AllowUserToAddRows = false;
            this.dgvList.AllowUserToDeleteRows = false;
            this.dgvList.AutoGenerateColumns = false;
            this.dgvList.BackgroundColor = System.Drawing.Color.White;
            this.dgvList.BorderStyle = Gizmox.WebGUI.Forms.BorderStyle.FixedSingle;
            this.dgvList.ColumnHeadersHeightSizeMode = Gizmox.WebGUI.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvList.Columns.AddRange(new Gizmox.WebGUI.Forms.DataGridViewColumn[] {
            this.colDB,
            this.colDESCRIPTION});
            this.dgvList.DataSource = this.bisDB;
            this.dgvList.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.dgvList.Location = new System.Drawing.Point(0, 0);
            this.dgvList.Name = "dgvList";
            //this.//dgvList.ReadOnly = true;
            this.dgvList.RowHeadersWidth = 25;
            this.dgvList.RowTemplate.DefaultCellStyle.FormatProvider = new System.Globalization.CultureInfo("en-US");
            this.dgvList.ShowFilterRow = true;
            this.dgvList.Size = new System.Drawing.Size(593, 416);
            this.dgvList.TabIndex = 0;
            this.dgvList.RowHeaderMouseDoubleClick += new Gizmox.WebGUI.Forms.DataGridViewCellMouseEventHandler(this.dgvList_RowHeaderMouseDoubleClick);
            // 
            // colDB
            // 
            this.colDB.DataPropertyName = "DB";
            this.colDB.HeaderText = "Database";
            this.colDB.Name = "colDB";
            this.colDB.ReadOnly = true;
            // 
            // colDESCRIPTION
            // 
            this.colDESCRIPTION.AutoSizeMode = Gizmox.WebGUI.Forms.DataGridViewAutoSizeColumnMode.Fill;
            this.colDESCRIPTION.DataPropertyName = "DESCRIPTION";
            this.colDESCRIPTION.HeaderText = "Description";
            this.colDESCRIPTION.Name = "colDESCRIPTION";
            this.colDESCRIPTION.ReadOnly = true;
            // 
            // bisDB
            // 
            this.bisDB.DataSource = typeof(DTO.DBAInfo);
            // 
            // tbDetail
            // 
            this.tbDetail.Controls.Add(this.gbFormat);
            this.tbDetail.Controls.Add(this.gbPara);
            this.tbDetail.Controls.Add(this.pibDATA_ACCESS_GROUP);
            this.tbDetail.Controls.Add(this.txtREPORT_TEMPLATE_DRIVER);
            this.tbDetail.Controls.Add(this.label4);
            this.tbDetail.Controls.Add(this.label3);
            this.tbDetail.Controls.Add(this.txtDATA_ACCESS_GROUP);
            this.tbDetail.Controls.Add(this.label2);
            this.tbDetail.Controls.Add(this.txtDESCRIPTION);
            this.tbDetail.Controls.Add(this.txtDB);
            this.tbDetail.Controls.Add(this.label1);
            this.tbDetail.Dock = Gizmox.WebGUI.Forms.DockStyle.Fill;
            this.tbDetail.Location = new System.Drawing.Point(0, 0);
            this.tbDetail.Name = "tbDetail";
            this.tbDetail.Size = new System.Drawing.Size(593, 416);
            this.tbDetail.TabIndex = 1;
            this.tbDetail.Text = "Detail";
            // 
            // gbFormat
            // 
            this.gbFormat.Controls.Add(this.label16);
            this.gbFormat.Controls.Add(this.txtTHOUSAND_SEPERATOR);
            this.gbFormat.Controls.Add(this.txtDECIMAL_SEPERATOR);
            this.gbFormat.Controls.Add(this.label15);
            this.gbFormat.Controls.Add(this.txtDECIMAL_PLACES_SUNACCOUNT);
            this.gbFormat.Controls.Add(this.txtDECIMAL_PLACES_SUNBUSINESS);
            this.gbFormat.Controls.Add(this.label14);
            this.gbFormat.Controls.Add(this.label6);
            this.gbFormat.Controls.Add(this.label5);
            this.gbFormat.Controls.Add(this.label13);
            this.gbFormat.Controls.Add(this.txtDATE_FORMAT);
            this.gbFormat.FlatStyle = Gizmox.WebGUI.Forms.FlatStyle.Flat;
            this.gbFormat.Location = new System.Drawing.Point(255, 113);
            this.gbFormat.Name = "gbFormat";
            this.gbFormat.Size = new System.Drawing.Size(260, 181);
            this.gbFormat.TabIndex = 3;
            this.gbFormat.TabStop = false;
            this.gbFormat.Text = "Formats";
            // 
            // label16
            // 
            this.label16.AutoSize = true;
            this.label16.Location = new System.Drawing.Point(3, 153);
            this.label16.Name = "label16";
            this.label16.Size = new System.Drawing.Size(35, 13);
            this.label16.TabIndex = 0;
            this.label16.Text = "Thousand seperator";
            // 
            // txtTHOUSAND_SEPERATOR
            // 
            this.txtTHOUSAND_SEPERATOR.Anchor = ((Gizmox.WebGUI.Forms.AnchorStyles)(((Gizmox.WebGUI.Forms.AnchorStyles.Top | Gizmox.WebGUI.Forms.AnchorStyles.Left)
                        | Gizmox.WebGUI.Forms.AnchorStyles.Right)));
            this.txtTHOUSAND_SEPERATOR.Location = new System.Drawing.Point(110, 150);
            this.txtTHOUSAND_SEPERATOR.Name = "txtTHOUSAND_SEPERATOR";
            this.txtTHOUSAND_SEPERATOR.Size = new System.Drawing.Size(144, 20);
            this.txtTHOUSAND_SEPERATOR.TabIndex = 4;
            // 
            // txtDECIMAL_SEPERATOR
            // 
            this.txtDECIMAL_SEPERATOR.Anchor = ((Gizmox.WebGUI.Forms.AnchorStyles)(((Gizmox.WebGUI.Forms.AnchorStyles.Top | Gizmox.WebGUI.Forms.AnchorStyles.Left)
                        | Gizmox.WebGUI.Forms.AnchorStyles.Right)));
            this.txtDECIMAL_SEPERATOR.Location = new System.Drawing.Point(110, 124);
            this.txtDECIMAL_SEPERATOR.Name = "txtDECIMAL_SEPERATOR";
            this.txtDECIMAL_SEPERATOR.Size = new System.Drawing.Size(144, 20);
            this.txtDECIMAL_SEPERATOR.TabIndex = 3;
            // 
            // label15
            // 
            this.label15.AutoSize = true;
            this.label15.Location = new System.Drawing.Point(3, 127);
            this.label15.Name = "label15";
            this.label15.Size = new System.Drawing.Size(35, 13);
            this.label15.TabIndex = 0;
            this.label15.Text = "Decimal seperator";
            // 
            // txtDECIMAL_PLACES_SUNACCOUNT
            // 
            this.txtDECIMAL_PLACES_SUNACCOUNT.Anchor = ((Gizmox.WebGUI.Forms.AnchorStyles)(((Gizmox.WebGUI.Forms.AnchorStyles.Top | Gizmox.WebGUI.Forms.AnchorStyles.Left)
                        | Gizmox.WebGUI.Forms.AnchorStyles.Right)));
            this.txtDECIMAL_PLACES_SUNACCOUNT.Location = new System.Drawing.Point(189, 72);
            this.txtDECIMAL_PLACES_SUNACCOUNT.Name = "txtDECIMAL_PLACES_SUNACCOUNT";
            this.txtDECIMAL_PLACES_SUNACCOUNT.Size = new System.Drawing.Size(65, 20);
            this.txtDECIMAL_PLACES_SUNACCOUNT.TabIndex = 1;
            // 
            // txtDECIMAL_PLACES_SUNBUSINESS
            // 
            this.txtDECIMAL_PLACES_SUNBUSINESS.Anchor = ((Gizmox.WebGUI.Forms.AnchorStyles)(((Gizmox.WebGUI.Forms.AnchorStyles.Top | Gizmox.WebGUI.Forms.AnchorStyles.Left)
                        | Gizmox.WebGUI.Forms.AnchorStyles.Right)));
            this.txtDECIMAL_PLACES_SUNBUSINESS.Location = new System.Drawing.Point(189, 98);
            this.txtDECIMAL_PLACES_SUNBUSINESS.Name = "txtDECIMAL_PLACES_SUNBUSINESS";
            this.txtDECIMAL_PLACES_SUNBUSINESS.Size = new System.Drawing.Size(65, 20);
            this.txtDECIMAL_PLACES_SUNBUSINESS.TabIndex = 2;
            // 
            // label14
            // 
            this.label14.AutoSize = true;
            this.label14.Location = new System.Drawing.Point(17, 101);
            this.label14.Name = "label14";
            this.label14.Size = new System.Drawing.Size(35, 13);
            this.label14.TabIndex = 0;
            this.label14.Text = "Bussiness Module Reference Data";
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Location = new System.Drawing.Point(17, 75);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(35, 13);
            this.label6.TabIndex = 0;
            this.label6.Text = "Ledger Acounting";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(3, 49);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(35, 13);
            this.label5.TabIndex = 0;
            this.label5.Text = "Decimal places";
            // 
            // label13
            // 
            this.label13.AutoSize = true;
            this.label13.Location = new System.Drawing.Point(3, 23);
            this.label13.Name = "label13";
            this.label13.Size = new System.Drawing.Size(35, 13);
            this.label13.TabIndex = 0;
            this.label13.Text = "Date format";
            // 
            // txtDATE_FORMAT
            // 
            this.txtDATE_FORMAT.Anchor = ((Gizmox.WebGUI.Forms.AnchorStyles)(((Gizmox.WebGUI.Forms.AnchorStyles.Top | Gizmox.WebGUI.Forms.AnchorStyles.Left)
                        | Gizmox.WebGUI.Forms.AnchorStyles.Right)));
            this.txtDATE_FORMAT.Location = new System.Drawing.Point(77, 20);
            this.txtDATE_FORMAT.Name = "txtDATE_FORMAT";
            this.txtDATE_FORMAT.Size = new System.Drawing.Size(177, 20);
            this.txtDATE_FORMAT.TabIndex = 0;
            // 
            // gbPara
            // 
            this.gbPara.Controls.Add(this.label12);
            this.gbPara.Controls.Add(this.txtPARAM_6);
            this.gbPara.Controls.Add(this.label11);
            this.gbPara.Controls.Add(this.txtPARAM_5);
            this.gbPara.Controls.Add(this.label10);
            this.gbPara.Controls.Add(this.txtPARAM_3);
            this.gbPara.Controls.Add(this.txtPARAM_4);
            this.gbPara.Controls.Add(this.label9);
            this.gbPara.Controls.Add(this.txtPARAM_1);
            this.gbPara.Controls.Add(this.label8);
            this.gbPara.Controls.Add(this.label7);
            this.gbPara.Controls.Add(this.txtPARAM_2);
            this.gbPara.Controls.Add(this.textBox6);
            this.gbPara.Controls.Add(this.textBox5);
            this.gbPara.FlatStyle = Gizmox.WebGUI.Forms.FlatStyle.Flat;
            this.gbPara.Location = new System.Drawing.Point(16, 113);
            this.gbPara.Name = "gbPara";
            this.gbPara.Size = new System.Drawing.Size(239, 181);
            this.gbPara.TabIndex = 4;
            this.gbPara.TabStop = false;
            this.gbPara.Text = "Parameter";
            // 
            // label12
            // 
            this.label12.AutoSize = true;
            this.label12.Location = new System.Drawing.Point(3, 153);
            this.label12.Name = "label12";
            this.label12.Size = new System.Drawing.Size(35, 13);
            this.label12.TabIndex = 0;
            this.label12.Text = "Param 6";
            // 
            // txtPARAM_6
            // 
            this.txtPARAM_6.Location = new System.Drawing.Point(59, 150);
            this.txtPARAM_6.MaxLength = 15;
            this.txtPARAM_6.Name = "txtPARAM_6";
            this.txtPARAM_6.Size = new System.Drawing.Size(174, 20);
            this.txtPARAM_6.TabIndex = 8;
            // 
            // label11
            // 
            this.label11.AutoSize = true;
            this.label11.Location = new System.Drawing.Point(3, 127);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(35, 13);
            this.label11.TabIndex = 0;
            this.label11.Text = "Param 5";
            // 
            // txtPARAM_5
            // 
            this.txtPARAM_5.Location = new System.Drawing.Point(59, 124);
            this.txtPARAM_5.MaxLength = 15;
            this.txtPARAM_5.Name = "txtPARAM_5";
            this.txtPARAM_5.Size = new System.Drawing.Size(174, 20);
            this.txtPARAM_5.TabIndex = 7;
            // 
            // label10
            // 
            this.label10.AutoSize = true;
            this.label10.Location = new System.Drawing.Point(3, 75);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(35, 13);
            this.label10.TabIndex = 0;
            this.label10.Text = "Param 3";
            // 
            // txtPARAM_3
            // 
            this.txtPARAM_3.Location = new System.Drawing.Point(59, 72);
            this.txtPARAM_3.MaxLength = 15;
            this.txtPARAM_3.Name = "txtPARAM_3";
            this.txtPARAM_3.Size = new System.Drawing.Size(174, 20);
            this.txtPARAM_3.TabIndex = 5;
            // 
            // txtPARAM_4
            // 
            this.txtPARAM_4.Location = new System.Drawing.Point(59, 98);
            this.txtPARAM_4.MaxLength = 15;
            this.txtPARAM_4.Name = "txtPARAM_4";
            this.txtPARAM_4.Size = new System.Drawing.Size(174, 20);
            this.txtPARAM_4.TabIndex = 6;
            // 
            // label9
            // 
            this.label9.AutoSize = true;
            this.label9.Location = new System.Drawing.Point(3, 101);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(35, 13);
            this.label9.TabIndex = 0;
            this.label9.Text = "Param 4";
            // 
            // txtPARAM_1
            // 
            this.txtPARAM_1.Location = new System.Drawing.Point(59, 20);
            this.txtPARAM_1.MaxLength = 15;
            this.txtPARAM_1.Name = "txtPARAM_1";
            this.txtPARAM_1.Size = new System.Drawing.Size(174, 20);
            this.txtPARAM_1.TabIndex = 3;
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Location = new System.Drawing.Point(3, 23);
            this.label8.Name = "label5";
            this.label8.Size = new System.Drawing.Size(35, 13);
            this.label8.TabIndex = 0;
            this.label8.Text = "Param 1";
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Location = new System.Drawing.Point(3, 49);
            this.label7.Name = "label6";
            this.label7.Size = new System.Drawing.Size(35, 13);
            this.label7.TabIndex = 0;
            this.label7.Text = "Param 2";
            // 
            // txtPARAM_2
            // 
            this.txtPARAM_2.Location = new System.Drawing.Point(59, 46);
            this.txtPARAM_2.MaxLength = 15;
            this.txtPARAM_2.Name = "txtPARAM_2";
            this.txtPARAM_2.Size = new System.Drawing.Size(174, 20);
            this.txtPARAM_2.TabIndex = 4;
            // 
            // textBox6
            // 
            this.textBox6.Location = new System.Drawing.Point(59, 46);
            this.textBox6.Name = "textBox6";
            this.textBox6.Size = new System.Drawing.Size(174, 20);
            this.textBox6.TabIndex = 1;
            // 
            // textBox5
            // 
            this.textBox5.Location = new System.Drawing.Point(59, 20);
            this.textBox5.Name = "textBox5";
            this.textBox5.Size = new System.Drawing.Size(174, 20);
            this.textBox5.TabIndex = 1;
            // 
            // pibDATA_ACCESS_GROUP
            // 
            this.pibDATA_ACCESS_GROUP.BackColor = System.Drawing.Color.Transparent;
            this.pibDATA_ACCESS_GROUP.BackgroundImageLayout = Gizmox.WebGUI.Forms.ImageLayout.Center;
            this.pibDATA_ACCESS_GROUP.Image = new Gizmox.WebGUI.Common.Resources.ImageResourceHandle(resources.GetString("pibDATA_ACCESS_GROUP.Image"));
            this.pibDATA_ACCESS_GROUP.Location = new System.Drawing.Point(182, 64);
            this.pibDATA_ACCESS_GROUP.Name = "pibDATA_ACCESS_GROUP";
            this.pibDATA_ACCESS_GROUP.Size = new System.Drawing.Size(20, 20);
            this.pibDATA_ACCESS_GROUP.SizeMode = Gizmox.WebGUI.Forms.PictureBoxSizeMode.CenterImage;
            this.pibDATA_ACCESS_GROUP.TabIndex = 2;
            this.pibDATA_ACCESS_GROUP.TabStop = false;
            this.pibDATA_ACCESS_GROUP.Click += new System.EventHandler(this.pibDATA_ACCESS_GROUP_Click);
            // 
            // txtREPORT_TEMPLATE_DRIVER
            // 
            this.txtREPORT_TEMPLATE_DRIVER.Location = new System.Drawing.Point(135, 90);
            this.txtREPORT_TEMPLATE_DRIVER.Name = "txtREPORT_TEMPLATE_DRIVER";
            this.txtREPORT_TEMPLATE_DRIVER.Size = new System.Drawing.Size(380, 20);
            this.txtREPORT_TEMPLATE_DRIVER.TabIndex = 3;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(16, 93);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(35, 13);
            this.label4.TabIndex = 0;
            this.label4.Text = "Report Template Path";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(16, 67);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(35, 13);
            this.label3.TabIndex = 0;
            this.label3.Text = "Group";
            // 
            // txtDATA_ACCESS_GROUP
            // 
            this.txtDATA_ACCESS_GROUP.Location = new System.Drawing.Point(79, 64);
            this.txtDATA_ACCESS_GROUP.MaxLength = 15;
            this.txtDATA_ACCESS_GROUP.Name = "txtDATA_ACCESS_GROUP";
            this.txtDATA_ACCESS_GROUP.Size = new System.Drawing.Size(100, 20);
            this.txtDATA_ACCESS_GROUP.TabIndex = 2;
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(16, 41);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(35, 13);
            this.label2.TabIndex = 0;
            this.label2.Text = "Description";
            // 
            // txtDESCRIPTION
            // 
            this.txtDESCRIPTION.Location = new System.Drawing.Point(79, 38);
            this.txtDESCRIPTION.Name = "txtDESCRIPTION";
            this.txtDESCRIPTION.Size = new System.Drawing.Size(436, 20);
            this.txtDESCRIPTION.TabIndex = 1;
            // 
            // txtDB
            // 
            this.txtDB.Location = new System.Drawing.Point(79, 12);
            this.txtDB.MaxLength = 3;
            this.txtDB.Name = "txtDB";
            this.txtDB.Size = new System.Drawing.Size(100, 20);
            this.txtDB.TabIndex = 0;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(16, 15);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "Database";
            // 
            // DB
            // 
            this.Controls.Add(this.tabControl1);
            this.DockPadding.All = 3;
            this.Location = new System.Drawing.Point(0, -10);
            this.Padding = new Gizmox.WebGUI.Forms.Padding(3);
            this.Size = new System.Drawing.Size(607, 448);
            this.Load += new System.EventHandler(this.DB_Load);
            ((System.ComponentModel.ISupportInitialize)(this.tabControl1)).EndInit();
            this.tabControl1.ResumeLayout(false);
            this.tbList.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dgvList)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.bisDB)).EndInit();
            this.tbDetail.ResumeLayout(false);
            this.gbFormat.ResumeLayout(false);
            this.gbPara.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.pibDATA_ACCESS_GROUP)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion


        #region IHostedApplication Members

        public void InitializeApplication()
        {
        }
        public string GetTitle()
        {
            return "Database";
        }
        public void addRecord()
        {

        }
        public void SetObject(object obj)
        {
        }


        public void OnToolBarButtonClick(HostedToolBarButton objButton, EventArgs objEvent)
        {
            try
            {
                sErr = "";
                string strAction = (string)objButton.Tag;

                BUS.DBAControl ctr = new BUS.DBAControl();
                switch (strAction)
                {
                    case "C":
                        tabControl1.SelectedTab = tbDetail;
                        RefeshForm("");
                        EnableForm(true);
                        break;
                    case "A":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.DBAInfo info = new DTO.DBAInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            if (txtDB.Text != info.DB)
                                SetData(info);
                            EnableForm(true);
                            txtDB.ReadOnly = true;
                            tabControl1.SelectedTab = tbDetail;
                        }
                        break;
                    case "S":
                        if (layout == null)
                            layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
                        layout.GetUpDGV(dgvList);
                        layout.SaveLayout();
                        Save(ctr);

                        break;
                    case "O":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.DBAInfo info = new DTO.DBAInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            SetData(info);
                            EnableForm(true);
                            tabControl1.SelectedTab = tbDetail;
                        }
                        break;
                    case "X":
                        Delete(ctr);

                        break;
                    case "TI":
                        Forms.frmTransferIn frmTI = new Forms.frmTransferIn(_strType, GetMainForm());
                        frmTI.ShowDialog();
                        break;
                    case "TO":
                        Forms.frmTransferOut frmTO = new Forms.frmTransferOut(_strType, GetMainForm());
                        frmTO.Show();
                        break;
                    case "R":
                        RefreshList();
                        break;
                    case "P":
                        if (dgvList.CurrentCell != null)
                        {
                            DTO.DBAInfo info = new DTO.DBAInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                            DataTable dt = DTO.DBAInfo.ToDataTable();
                            dt.Rows.Add(info.ToDataRow(dt));
                            DataSet ds = new DataSet();
                            ds.Tables.Add(dt);
                            MainForm main = GetMainForm();
                            if (main != null)
                                main.PrintDataSet(ds, _strType);
                        }
                        break;
                }
                _processStatus = strAction;
                if (sErr == "")
                    ThrowMsg("Command: " + _processStatus);
            }
            catch (Exception ex)
            {
                ThrowMsg(ex.Message + Environment.NewLine + ex.Source);
            }
        }

        private void RefreshList()
        {
            GetMainForm().LoadDataTable(_strType);
            Rebind();
            if (layout == null)
                layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
            layout.ResetLayout();
            layout.SetUpDGV(dgvList);
        }

        private void Delete(BUS.DBAControl ctr)
        {
            if (dgvList.CurrentCell != null)
            {
                DTO.DBAInfo info = new DTO.DBAInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                if (ctr.IsExist(info.DB))
                {
                    Forms.frmMsg frm = new Forms.frmMsg();
                    frm.FormClosed += delegate(object form, FormClosedEventArgs args)
                    {
                        if (((Gizmox.WebGUI.Forms.Form)form).DialogResult == DialogResult.OK)
                        {
                            ctr.Delete(info.DB);
                            if (sErr == "")
                            {
                                GetMainForm().RemoveRecord(_strType, ((DataRowView)dgvList.CurrentRow.DataBoundItem).Row);
                                EnableForm(false);
                                Rebind();
                                sErr = "Delete record " + info.DB + " successful";
                            }

                            ThrowMsg(sErr);

                        }

                    };
                    frm.ShowMsg("Do you want to delete " + info.DB + "?");

                }
                else
                    sErr = clsConfigurarion.GetErrMsg("E0002", language);// "Data is not exist";
            }
        }

        private void Save(BUS.DBAControl ctr)
        {
            if (tabControl1.SelectedTab == tbDetail)
            {
                DTO.DBAInfo info = GetData();
                if (_processStatus == "A")
                {
                    if (ctr.IsExist(txtDB.Text))
                    {
                        sErr = ctr.Update(info);
                        UpdateRecord(info);
                        sErr = "Update record " + txtDB.Text + " successful";
                    }
                    else
                        sErr = clsConfigurarion.GetErrMsg("E0002", language);// "Data is not exist";
                }
                else if (_processStatus == "C" || _processStatus == "O")
                {
                    if (!ctr.IsExist(txtDB.Text))
                    {
                        ctr.Add(info, ref sErr);
                        UpdateRecord(info);
                        sErr = "Add record " + txtDB.Text + " successful";
                    }
                    else
                        sErr = clsConfigurarion.GetErrMsg("E0007", language);
                }
                ThrowMsg(sErr);

            }
        }

        private void UpdateRecord(DTO.DBAInfo info)
        {
            GetMainForm().GetTable(_strType).BeginLoadData();
            GetMainForm().UpdateRecord(_strType, info.ToDataRow(GetMainForm().GetTable(_strType)).ItemArray, LoadOption.OverwriteChanges);
            GetMainForm().GetTable(_strType).EndLoadData();
            EnableForm(false);
            Rebind();
        }
        private void Rebind()
        {
            bisDB.DataSource = GetMainForm().GetTable(_strType);
        }
        private void ThrowMsg(string sErr)
        {
            BaseForm x = this.Parent.Parent as BaseForm;
            if (x != null)
            {
                x.SetMsg(sErr);
            }
        }

        private DTO.DBAInfo GetData()
        {
            return new DTO.DBAInfo(txtDB.Text
                , txtDB.Text
                , txtDB.Text
                , txtDESCRIPTION.Text
                , txtDATE_FORMAT.Text
                , txtDECIMAL_PLACES_SUNACCOUNT.Text
               , txtDECIMAL_SEPERATOR.Text
                , txtTHOUSAND_SEPERATOR.Text
                , ""
                , txtDATA_ACCESS_GROUP.Text
                , txtDECIMAL_PLACES_SUNBUSINESS.Text
                , txtREPORT_TEMPLATE_DRIVER.Text
                , txtPARAM_1.Text
                , txtPARAM_2.Text
                , txtPARAM_3.Text
                , txtPARAM_4.Text
                , txtPARAM_5.Text
                , txtPARAM_6.Text
                );

        }

        private void EnableForm(bool p)
        {
            txtPARAM_6.ReadOnly = !p;
            txtPARAM_5.ReadOnly = !p;
            txtPARAM_4.ReadOnly = !p;
            txtPARAM_3.ReadOnly = !p;
            txtPARAM_2.ReadOnly = !p;
            txtPARAM_1.ReadOnly = !p;
            txtDESCRIPTION.ReadOnly = !p;
            txtDECIMAL_SEPERATOR.ReadOnly = !p;
            txtDECIMAL_PLACES_SUNBUSINESS.ReadOnly = !p;
            txtDECIMAL_PLACES_SUNACCOUNT.ReadOnly = !p;
            txtDB.ReadOnly = !p;
            txtDATE_FORMAT.ReadOnly = !p;
            txtDATA_ACCESS_GROUP.ReadOnly = !p;
            pibDATA_ACCESS_GROUP.Enabled = p;

        }

        private void SetData(DTO.DBAInfo info)
        {
            txtPARAM_6.Text = info.PARAM_6;
            txtPARAM_5.Text = info.PARAM_5;
            txtPARAM_4.Text = info.PARAM_4;
            txtPARAM_3.Text = info.PARAM_3;
            txtPARAM_2.Text = info.PARAM_2;
            txtPARAM_1.Text = info.PARAM_1;
            txtDESCRIPTION.Text = info.DESCRIPTION;
            txtDECIMAL_SEPERATOR.Text = info.DECIMAL_SEPERATOR;
            txtDECIMAL_PLACES_SUNBUSINESS.Text = info.DECIMAL_PLACES_SUNBUSINESS;
            txtDECIMAL_PLACES_SUNACCOUNT.Text = info.DECIMAL_PLACES_SUNACCOUNT;
            txtDB.Text = info.DB;
            txtDATE_FORMAT.Text = info.DATE_FORMAT;
            txtDATA_ACCESS_GROUP.Text = info.DATA_ACCESS_GROUP;
        }

        private void RefeshForm(string str)
        {
            txtPARAM_6.Text = str;
            txtPARAM_5.Text = str;
            txtPARAM_4.Text = str;
            txtPARAM_3.Text = str;
            txtPARAM_2.Text = str;
            txtPARAM_1.Text = str;
            txtDESCRIPTION.Text = str;
            txtDECIMAL_SEPERATOR.Text = str;
            txtDECIMAL_PLACES_SUNBUSINESS.Text = str;
            txtDECIMAL_PLACES_SUNACCOUNT.Text = str;
            txtDB.Text = str;
            txtDATE_FORMAT.Text = str;
            txtDATA_ACCESS_GROUP.Text = str;
        }

        #endregion

        private void DB_Load(object sender, EventArgs e)
        {
            dgvList.AutoGenerateColumns = false;
            if (!GetMainForm().IsContainsTables(_strType))
                GetMainForm().LoadDataTable(_strType);
            Rebind();
            EnableForm(false);
            layout = new GridLayout(MainForm.ServerPath + "Resources\\Layout\\", MainForm.ServerPath + "Documents\\Layout\\" + GetMainForm().PODInfo.USER_ID + "\\", _strType);
            //layout.LoadLayout();
            layout.SetUpDGV(dgvList);
            if (idAllowEditLanguage >= GetMainForm().Permission.Length || GetMainForm().Permission[idAllowEditLanguage] == 'Y')
                AllowEditLanguage();

        }

        private void dgvList_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (dgvList.CurrentCell != null)
            {
                DTO.DBAInfo info = new DTO.DBAInfo((DataRowView)dgvList.CurrentRow.DataBoundItem);
                SetData(info);
                EnableForm(false);
                tabControl1.SelectedTab = tbDetail;
                _processStatus = "V";
            }
        }

        private void pibDATA_ACCESS_GROUP_Click(object sender, EventArgs e)
        {
            Forms.frmView frm = new Forms.frmView("DA", GetMainForm());
            frm.FormClosed += delegate(object form, FormClosedEventArgs args)
            {
                if (((Forms.frmView)form).DialogResult == DialogResult.OK)
                {
                    txtDATA_ACCESS_GROUP.Text = ((Forms.frmView)form).ReturnValue[((Forms.frmView)form).ReturnValue.Table.PrimaryKey[0]].ToString();
                }
            };
            frm.ShowDialog();
        }

        public string GetLanguage()
        {
            return language;
        }


    }
}
